package com.example.administrator.waitan.main;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.waitan.R;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/1/11.
 */
public class MainViewPagerAdapter extends FragmentPagerAdapter {
    private ArrayList<Fragment> data;
    private Context context;
    String title1 = "首页";
    String title2 = "热门";
    String title3 = "发现";
    String title4 = "我的";
    String [] titles = {title1,title2,title3,title4};//设置底部tablayoutout显示文字
    private int [] imageviewId = {R.drawable.homepager_tab,R.drawable.hot_tab,R.drawable.find_tab,R.drawable.mine_tab};
    public MainViewPagerAdapter(FragmentManager fm,Context context,ArrayList<Fragment> data) {
        super(fm);
        this.context = context;
        this.data = data;
    }

    @Override
    public Fragment getItem(int position) {
        return data.get(position);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return null;
    }
    public View getTabView(int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.tab_main, null);
        TextView textview = (TextView) view.findViewById(R.id.tab_main_tv);
        ImageView imageview = (ImageView) view.findViewById(R.id.tab_main_iv);
        textview.setText(titles[position]);
        imageview.setImageResource(imageviewId[position]);
        return view;
    }

//    @Override
//    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
//    }
}
